import java.nio.FloatBuffer;
import java.nio.IntBuffer;

import javax.media.opengl.GL;
import javax.media.opengl.GL2;

import com.jogamp.common.nio.Buffers;


public class Pyramid extends Shape {

	
	public Pyramid(float s){
		centerX = 0;
		centerY = 0;
		centerZ = 0;
		scale = s;
	}

	public void draw(GL2 gl){
		float[] v = { 
			   0.0f,  1.0f,  0.0f,  
			   -1.0f, -1.0f,  1.0f, 
			    1.0f, -1.0f,  1.0f,  
			    1.0f, -1.0f, -1.0f,  
			   -1.0f, -1.0f, -1.0f  
			  };
		float[] n = { 
				   0.0f,  1.0f,  0.0f,  
				   -1.0f, -1.0f,  1.0f, 
				    1.0f, -1.0f,  1.0f,  
				    1.0f, -1.0f, -1.0f,  
				   -1.0f, -1.0f, -1.0f  
				  };
		int [] index = { 
				0, 1, 2, //front
				0, 2, 3, //right
				0, 3, 4, //back
				0, 4, 1, // left
				3, 2, 1, //Bottom 1
				4, 3, 1, //Bottom 2
			 };
		
		normal = n;
		vert = performTransform(v, true);
		
		FloatBuffer vBuf = Buffers.newDirectFloatBuffer(vert.length);
		vBuf.put(vert);
		vBuf.rewind();
		FloatBuffer nBuf = Buffers.newDirectFloatBuffer(normal.length);
		nBuf.put(normal);
		nBuf.rewind();
		iBuf = Buffers.newDirectIntBuffer(index.length);
		iBuf.put(index);
		iBuf.rewind();
		
		gl.glMatrixMode(GL2.GL_MODELVIEW);
		gl.glPushMatrix();

		gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
		gl.glEnableClientState(GL2.GL_NORMAL_ARRAY);

		gl.glVertexPointer(3, GL2.GL_FLOAT, 0, vBuf);
		gl.glNormalPointer(GL2.GL_FLOAT, 0, nBuf);
		gl.glColor3f(1.0f, color, 0.0f); // Red
		gl.glDrawElements(GL2.GL_TRIANGLES, 18, GL2.GL_UNSIGNED_INT, iBuf);
		gl.glPopMatrix();

	}	
}